import {fileURLToPath, URL} from 'node:url'

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'

//Element按需引入的插件
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'

// 导入ElementPlus定制主题配置对应包
import ElementPlus from 'unplugin-element-plus/vite'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver({importStyle: "sass"})],
        }),
        // 按需定制主题配置
        ElementPlus({
            useSource: true,
        }),
    ],
    server: {
        host: "0.0.0.0",
        cors: true,
        port: 8991,
        open: false, //自动打开
        proxy: {
          // 这里的ccc可乱写, 是拼接在url后面的地址 如果接口中没有统一的后缀可自定义
          // 如果有统一后缀, 如api, 直接写api即可, 也不用rewrite了
          "^/api": {
            target: "http://127.0.0.1:63010", // 真实接口地址, 后端给的基地址
            changeOrigin: true, // 允许跨域
            rewrite: (path) => path.replace(/^\/api/, ""), // 将ccc替换为空
          },
        },
      },
    resolve: {
        
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                // 自动导入定制化样式文件进行样式覆盖
                additionalData: `
          @use "@/styles/element/index.scss" as *;
          @use "@/styles/common.scss" as *;
          @use "@/styles/var.scss" as *;
        `,
            }
        }
    }
})
